<?php
/**
 * Created by PhpStorm.
 * User: wangsentao
 * Date: 2018/1/30
 * Time: 下午12:28
 */

namespace app\platform\controller;

use app\common\ShaoHuoPay\Pay;

class Wx
{
    protected $config;

    public function __construct()
    {
        $this->config = [
            'appid' => config('pay')['WX_PAY']['APPID'], // APP APPID
            'app_id' => config('pay')['WX_MP_PAY']['APPID'], // 公众号 APPID
            'miniapp_id' => config('pay')['WX_WECHAT_PAY']['APPID'], // 小程序 APPID
            'mch_id' => config('pay')['WX_MCHID'],
            'key' => config('pay')['WX_KEY'],
            'notify_url' => config('pay')['WX_NOTIFUL'],
            'cert_client' => '', // optional，退款等情况时用到
            'cert_key' => '',// optional，退款等情况时用到
            'mode' => 'dev', // optional
        ];
    }

    public function appPay()
    {
        $order = [
            'out_trade_no' => GenOrderId(),//生成系统订单号
            'total_fee' => '1', // **单位：分**
            'body' => 'test body - 测试',
            'openid' => '',
        ];

        $pay = Pay::wechat($this->config)->mp($order);
    }

    /**
     * 公众号
     */
    public function mpPay()
    {
        $order = [
            'out_trade_no' => GenOrderId(),//生成系统订单号
            'body' => 'subject-测试',
            'total_fee' => '1',
            'openid' => 'onkVf1FjWS5SBxxxxxxxx',
        ];

        $result = Pay::wechat($this->config)->mp($order);
    }

    /**
     * 小程序
     */
    public function miniPay()
    {
        $order = [
            'out_trade_no' => GenOrderId(),//生成系统订单号
            'body' => 'subject-测试',
            'total_fee' => '1',
            'openid' => 'onkVf1FjWS5SBxxxxxxxx',
        ];

        $result = Pay::wechat($this->config)->miniapp($order);
    }
}